
#include "RingBuf.h"

/*-------------------------------------------------------
                 Modulglobal Variables 
---------------------------------------------------------*/


void InitBuffer(struct RingBuf *Buf, unsigned int pLen, unsigned char *pData)
/*----------------------------------------------------------------------------
Beschreibung....: Inits TX ring buf
INPUT ..........: --
OUTPUT .........: TxRingBuf
RETURN..........: --
AUTOR...........: BA Fn - Ilg
DATUM...........: 15.11.2005
------------------------------------------------------------------------------*/
{
	Buf->GetPos = 0;  
	Buf->SetPos = 0;
	Buf->Length = pLen;
	Buf->Content = 0;
	Buf->Data = pData;
}


void AddByte(struct RingBuf* Buf, unsigned char ByteToWrite)
/*----------------------------------------------------------------------------
Beschreibung....: Adds one byte to buffer
INPUT ..........: Pointer to buffer, Data to insert
OUTPUT .........: Buffer
RETURN..........: --
AUTOR...........: BA Fn - Ilg
DATUM...........: 15.11.2005
------------------------------------------------------------------------------*/
{
	Buf->Data[Buf->SetPos++] = ByteToWrite;
	if (Buf->SetPos >= Buf->Length)
		Buf->SetPos = 0;  // Borders of buffer achieved
	Buf->Content++;
}

unsigned char GetByte(struct RingBuf *Buf)
/*----------------------------------------------------------------------------
Beschreibung....: Gets one byte from buffer
INPUT ..........: Pointer to buffer
OUTPUT .........: --
RETURN..........: Data byte from buffer
AUTOR...........: BA Fn - Ilg
DATUM...........: 15.11.2005
------------------------------------------------------------------------------*/
{
	unsigned char RetVal;	
	RetVal = Buf->Data[Buf->GetPos++];
	if (Buf->GetPos >= Buf->Length)
		Buf->GetPos = 0; 	// Borders of buffer achieved
	Buf->Content --;
	return RetVal;	
}

